package com.poh.service.impl;

import com.poh.mapper.CouserMapper;
import com.poh.pojo.Course;
import com.poh.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Random;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    CouserMapper couserMapper;

    @Override
    public List<Course> getCourseByUserId(int userId) {
        return couserMapper.getCourseByUserId(userId);
    }

    @Override
    public List<Course> getCourseByTeach(int userId) {
        return couserMapper.getCourseByTeach(userId);
    }


    @Override
    public int createCourse(Course course) {
        Random random = new Random();
        String code = String.valueOf(random.nextInt(1000));
        course.setInvitationCode(code);
        int i = couserMapper.createCourse(course);
        return i;
    }

    @Override
    public Course getCourseByCourseId(int courseId) {
        return couserMapper.getCourseByCourseId(courseId);
    }

    @Override
    public int updateImgByCourseId(int courseId, String courseImg) {
        return couserMapper.updateImgByCourseId(courseId, courseImg);
    }
}
